package cn.xxi.ai.application.dto;

import cn.xxi.ai.util.MapCleaner;
import lombok.Getter;

import java.util.Map;

@Getter
public class NodeStarted extends StartedEvent<Map<String, Object>> {

    private final String nodeId;
    private final String nodeType;
    private final String title;
    private final Map<String, Object> inputs;

    public NodeStarted(String nodeId, String nodeType, String title, Map<String, Object> inputs) {
        this.nodeId = nodeId;
        this.nodeType = nodeType;
        this.title = title;
        this.inputs = inputs;
    }

    @Override
    public boolean persistent() {
        return false;
    }

    @Override
    public FinishedEvent toSuccessEvent(Map<String, Object> outputs) {
        return new NodeFinished(nodeId, nodeType, title, inputs, MapCleaner.clean(outputs), Status.SUCCESS, null, startedAt);
    }

    @Override
    public FinishedEvent toFailureEvent(String error) {
        return new NodeFinished(nodeId, nodeType, title, inputs, Map.of(), Status.FAILURE, error, startedAt);
    }
}
